<?php  
class ControllerCommonColumnLeft extends Controller {
	public function index() {
		$this->load->model('design/layout');
		$this->load->model('catalog/category');
		$this->load->model('catalog/product');
		$this->load->model('catalog/information');
		
		if (isset($this->request->get['route'])) {
			$route = (string)$this->request->get['route'];
		} else {
			$route = 'common/home';
		}
		
		$layout_id = 0;
		
		if ($route == 'product/category' && isset($this->request->get['path'])) {
			$path = explode('_', (string)$this->request->get['path']);
				
			$layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));			
		}
		
		if ($route == 'product/product' && isset($this->request->get['product_id'])) {
			$layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
		}
		
		if ($route == 'information/information' && isset($this->request->get['information_id'])) {
			$layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
		}
		
		if (!$layout_id) {
			$layout_id = $this->model_design_layout->getLayout($route);
		}
						
		if (!$layout_id) {
			$layout_id = $this->config->get('config_layout_id');
		}

		$module_data = array();
		
		$this->load->model('setting/extension');
		
		$extensions = $this->model_setting_extension->getExtensions('module');		
		
		foreach ($extensions as $extension) {
			$modules = $this->config->get($extension['code'] . '_module');
		
			if ($modules) {
				foreach ($modules as $module) {
					if ($module['layout_id'] == $layout_id && $module['position'] == 'column_left' && $module['status']) {
						$module_data[] = array(
							'code'       => $extension['code'],
							'setting'    => $module,
							'sort_order' => $module['sort_order']
						);				
					}
				}
			}
		}
		
		$sort_order = array(); 
	  
		foreach ($module_data as $key => $value) {
      		$sort_order[$key] = $value['sort_order'];
    	}
		
		array_multisort($sort_order, SORT_ASC, $module_data);
		
		$this->data['modules'] = array();
		
		foreach ($module_data as $module) {
			$module = $this->getChild('module/' . $module['code'], $module['setting']);
			
			if ($module) {
				$this->data['modules'][] = $module;
			}
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/column_left.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/column_left.tpl';
		} else {
			$this->template = 'default/template/common/column_left.tpl';
		}

        if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
            $server = HTTPS_IMAGE;
        } else {
            $server = HTTP_IMAGE;
        }

        $this->data['home_link']=HTTP_SERVER;
        $this->data['name']=$this->config->get('config_name');
        $this->data['left_column_yellow_submarin']=HTTP_IMAGE.'data/yellowrec.gif';

        if($this->config->get('config_logo') && file_exists(DIR_IMAGE.$this->config->get('config_logo'))){
            $this->data['logo']=$server.$this->config->get('config_logo');
        }else{
            $this->data['logo']='';
        }

        $this->load->language('common/column_left');
        $this->load->model('catalog/information');

        $this->data['information_links']=array();

        if($informations=$this->model_catalog_information->getInformations()){
            $this->load->helper('html');

            foreach($informations as $info){
                if($info['left_menu']){
                    $this->data['information_links'][]=getUrl(array(
                        'container'=>'p',
                        'container_class'=>'information-links',
                        'data_url'=>$this->url->link('information/information', 'information_id='.$info['information_id']),
                        'href'=>$this->url->link('information/information', 'information_id='.$info['information_id']),
                        'text'=>$info['title'],
                    ));
                }
            }
        }

        if($this->customer->isLogged()){
            $this->language->load('common/header');
            $this->data['information_links'][]=getUrl(array(
                'container'=>'p',
                'container_class'=>'information-links',
                'data_url'=>$this->url->link('account/account', '', 'SSL'),
                'href'=>$this->url->link('account/account', '', 'SSL'),
                'text'=>$this->language->get('text_account'),
            ));
        }

        $this->children=array(
            'account/loginForm',
        );

		$this->render();
	}
}
?>